package com.naihe.anderson.sms.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.Button;

import com.naihe.anderson.sms.R;
import com.naihe.anderson.sms.adapter.GalleryImageAdapter;
import com.naihe.anderson.sms.application.NhSmsApp;
import com.naihe.anderson.sms.widgets.GalleryFlow;

public class GalleryActivity extends Activity implements OnClickListener, OnItemClickListener, OnItemLongClickListener {
	public static final int REQUEST_UCNOTE_CODE = 12;

	Button create_btn;
	Button back_btn;
	GalleryFlow galleryFlow;
	
	GalleryImageAdapter imageAdapter;
	
	NhSmsApp nhSmsApp;
	
	public static final int MSG_WHAT_DATA_CHANGE = 0;
	public static final int MSG_WHAT_MENU_DEL_NOTE = 1;
	Handler mHandler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			switch (msg.what) {
			case MSG_WHAT_DATA_CHANGE:
				
				break;
			default:
				break;
			}
		}
		
	};

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.gallery_layout);
		nhSmsApp = (NhSmsApp) getApplication();
		
		initView();
	}
	

	public void initView() {
		//
		imageAdapter = new GalleryImageAdapter(GalleryActivity.this, null);
		galleryFlow = (GalleryFlow) this.findViewById(R.id.gallery);
		galleryFlow.setFadingEdgeLength(0);
        galleryFlow.setSpacing(-50); //图片之间的间距
        galleryFlow.setAdapter(imageAdapter);
        galleryFlow.setOnItemClickListener(this);
        
		create_btn = (Button) findViewById(R.id.create_btn);
		create_btn.setOnClickListener(this);

		back_btn = (Button) findViewById(R.id.back_btn);
		back_btn.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.create_btn) {
			
		} else if (v.getId() == R.id.back_btn) {
			finish();
			System.gc();
		}
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// 截获按键事件
		if (KeyEvent.KEYCODE_BACK == keyCode) {
			
			return super.onKeyDown(keyCode, event);
		}

		return super.onKeyDown(keyCode, event);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		if(data == null || data.getExtras() == null)
			return;
		if (requestCode == REQUEST_UCNOTE_CODE && resultCode == RESULT_OK) {
			
		}
	}


	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position,
			long id) {
		
	}


	@Override
	public boolean onItemLongClick(AdapterView<?> parent, View view,
			int position, long id) {
		
		return false;
	}
	
}
